{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "313ec317",
   "metadata": {},
   "source": [
    "---\n",
    "· 日期：2022-10-26\\week10(周三)\n",
    "\n",
    "· 课程：python\n",
    "\n",
    "· 记录人：林荣烽\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a7437d4",
   "metadata": {},
   "source": [
    "购物车程序项目：\n",
    "\n",
    "要求：\n",
    "1、运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "\n",
    "2、让用户输入商品编号进行商品的购买。\n",
    "\n",
    "3、用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "\n",
    "4、用户可以随时退出购买，退出时打印用户已购买的商品和支付宝余额。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18676cb6",
   "metadata": {},
   "outputs": [],
   "source": [
    "准备工作：\n",
    "product_list = [\"自行车 299\",\n",
    "                \"Iphone 14 Pro 8000\",\n",
    "               \"NFT 盲盒 28\"，\n",
    "               \"许老师的Python书 80\"\n",
    "               ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5d31a2f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 优化\n",
    "product_list = [ [\"自行车 299\",],\n",
    "                [\"Iphone 14 Pro 8000\",]\n",
    "                [\"NFT 盲盒 28\",]\n",
    "               [\"许老师的Python书 80\"]\n",
    "               ]\n",
    "shopping_car = []\n",
    "1. Alipay = input(\"请输入余额:\")\n",
    "   print()\n",
    "    # 情景1：用户输入了商品编号:shopping\n",
    "2. user_choice = input(\"请输入商品编号:\")\n",
    "   # 0,1,2,3\n",
    "3. if 钱够，Alipay - 商品的价格\n",
    "      shopping_car.append(product_list[user_choice])\n",
    "   else print(\"您的余额已不足，请更换支付方式~\")\n",
    "4. # 情景2：用户输入\"q\",退出购买\n",
    "   print(shopping_car)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "ae04057f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in range(4):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "a993c1ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额：50000\n",
      "---------商品列表--------\n",
      "商品编号: 0 ['自行车', 299]\n",
      "商品编号: 1 ['Iphone 14 Pro', 8000]\n",
      "商品编号: 2 ['NFT 盲盒', 28]\n",
      "商品编号: 3 ['许老师的Python书', 80]\n",
      "请输入商品编号：3\n",
      "您购买的商品已增加到购物车~~您的余额还有: 49920\n",
      "---------商品列表--------\n",
      "商品编号: 0 ['自行车', 299]\n",
      "商品编号: 1 ['Iphone 14 Pro', 8000]\n",
      "商品编号: 2 ['NFT 盲盒', 28]\n",
      "商品编号: 3 ['许老师的Python书', 80]\n",
      "请输入商品编号：1\n",
      "您购买的商品已增加到购物车~~您的余额还有: 41920\n",
      "---------商品列表--------\n",
      "商品编号: 0 ['自行车', 299]\n",
      "商品编号: 1 ['Iphone 14 Pro', 8000]\n",
      "商品编号: 2 ['NFT 盲盒', 28]\n",
      "商品编号: 3 ['许老师的Python书', 80]\n",
      "请输入商品编号：1\n",
      "您购买的商品已增加到购物车~~您的余额还有: 33920\n",
      "---------商品列表--------\n",
      "商品编号: 0 ['自行车', 299]\n",
      "商品编号: 1 ['Iphone 14 Pro', 8000]\n",
      "商品编号: 2 ['NFT 盲盒', 28]\n",
      "商品编号: 3 ['许老师的Python书', 80]\n",
      "请输入商品编号：q\n",
      "您的购物车: []\n",
      "您的余额还有: 33920\n"
     ]
    }
   ],
   "source": [
    "product_list = [\n",
    "    [\"自行车\",299],\n",
    "    [\"Iphone 14 Pro\", 8000],\n",
    "    [\"NFT 盲盒\", 28],\n",
    "    [\"许老师的Python书\",80]\n",
    "]\n",
    "\n",
    "shopping_car = []\n",
    "\n",
    "Alipay = int(input(\"请输入余额：\"))\n",
    "while True:\n",
    "    print(\"---------商品列表--------\")\n",
    "    for i in range(4):\n",
    "        print(\"商品编号: \"+str(i),product_list[i])\n",
    "    user_chioce = input(\"请输入商品编号：\")\n",
    "    # 情景1：用户输入了商品编号：shopping\n",
    "    if user_chioce.isdigit():\n",
    "        # 判断钱够不够，商品是谁？ ==> product_list[user_chioce][1]\n",
    "        if Alipay >= product_list[int(user_chioce)][1]:\n",
    "            Alipay = Alipay - product_list[int(user_chioce)][1] # 买完商品剩余的钱\n",
    "            print(\"您购买的商品已增加到购物车~~您的余额还有:\",Alipay)\n",
    "        else:\n",
    "            print(\"您的余额不足，请更换支付方式~~\")\n",
    "    # 情景2：用户输入\"q\",退出购买\n",
    "    elif user_chioce == \"q\":\n",
    "        print(\"您的购物车:\",shopping_car)\n",
    "        print(\"您的余额还有:\",Alipay)\n",
    "        break\n",
    "    else:\n",
    "        print(\"您输入的商品不存在或输入有误，请重新尝试\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "33ccbdf5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting pyecharts\n",
      "  Downloading pyecharts-1.9.1-py3-none-any.whl (135 kB)\n",
      "Requirement already satisfied: jinja2 in c:\\programdata\\anaconda3\\lib\\site-packages (from pyecharts) (2.11.3)\n",
      "Collecting prettytable\n",
      "  Downloading prettytable-3.4.1-py3-none-any.whl (26 kB)\n",
      "Collecting simplejson\n",
      "  Downloading simplejson-3.17.6-cp38-cp38-win_amd64.whl (75 kB)\n",
      "Requirement already satisfied: MarkupSafe>=0.23 in c:\\programdata\\anaconda3\\lib\\site-packages (from jinja2->pyecharts) (1.1.1)\n",
      "Requirement already satisfied: wcwidth in c:\\programdata\\anaconda3\\lib\\site-packages (from prettytable->pyecharts) (0.2.5)\n",
      "Installing collected packages: simplejson, prettytable, pyecharts\n",
      "Successfully installed prettytable-3.4.1 pyecharts-1.9.1 simplejson-3.17.6\n"
     ]
    }
   ],
   "source": [
    "!pip install pyecharts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "59e9283d",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unexpected EOF while parsing (<ipython-input-7-bef57f695d18>, line 17)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-7-bef57f695d18>\"\u001b[1;36m, line \u001b[1;32m17\u001b[0m\n\u001b[1;33m    )\u001b[0m\n\u001b[1;37m     ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n"
     ]
    }
   ],
   "source": [
    "import pyecharts.options as opts\n",
    "from pyecharts.charts import Line\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "c = (\n",
    "     Line()\n",
    "     .add_xaxis(Faker.choose()\n",
    "     .add_yaxis(\n",
    "     \"商家A\",\n",
    "     Faker.values(),\n",
    "     markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_=\"min\")]),\n",
    "     )\n",
    "     .add_yaxis(\n",
    "     \"商家B\",\n",
    "     Faker.values(),\n",
    "     markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_=\"max\")]),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "88532944",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pyautogui'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-8-bc051d8eef82>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mpyautogui\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mtime\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pyautogui'"
     ]
    }
   ],
   "source": [
    "import pyautogui\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "90808b74",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting pyautogui\n",
      "  Downloading PyAutoGUI-0.9.53.tar.gz (59 kB)\n",
      "Collecting pymsgbox\n",
      "  Downloading PyMsgBox-1.0.9.tar.gz (18 kB)\n",
      "  Installing build dependencies: started\n",
      "  Installing build dependencies: finished with status 'done'\n",
      "  Getting requirements to build wheel: started\n",
      "  Getting requirements to build wheel: finished with status 'done'\n",
      "    Preparing wheel metadata: started\n",
      "    Preparing wheel metadata: finished with status 'done'\n",
      "Collecting PyTweening>=1.0.1\n",
      "  Downloading pytweening-1.0.4.tar.gz (14 kB)\n",
      "Collecting pyscreeze>=0.1.21\n",
      "  Downloading PyScreeze-0.1.28.tar.gz (25 kB)\n",
      "  Installing build dependencies: started\n",
      "  Installing build dependencies: finished with status 'done'\n",
      "  Getting requirements to build wheel: started\n",
      "  Getting requirements to build wheel: finished with status 'done'\n",
      "    Preparing wheel metadata: started\n",
      "    Preparing wheel metadata: finished with status 'done'\n",
      "Collecting pygetwindow>=0.0.5\n",
      "  Downloading PyGetWindow-0.0.9.tar.gz (9.7 kB)\n",
      "Collecting mouseinfo\n",
      "  Downloading MouseInfo-0.1.3.tar.gz (10 kB)\n",
      "Collecting pyrect\n",
      "  Downloading PyRect-0.2.0.tar.gz (17 kB)\n",
      "Requirement already satisfied: Pillow>=6.2.1 in c:\\programdata\\anaconda3\\lib\\site-packages (from pyscreeze>=0.1.21->pyautogui) (8.2.0)\n",
      "Collecting pyperclip\n",
      "  Downloading pyperclip-1.8.2.tar.gz (20 kB)\n",
      "Building wheels for collected packages: pyautogui, pygetwindow, pyscreeze, PyTweening, mouseinfo, pymsgbox, pyperclip, pyrect\n",
      "  Building wheel for pyautogui (setup.py): started\n",
      "  Building wheel for pyautogui (setup.py): finished with status 'done'\n",
      "  Created wheel for pyautogui: filename=PyAutoGUI-0.9.53-py3-none-any.whl size=36583 sha256=2df2a5a82229722f1b18348da1b535c61313af1507c7d1a80844101b1ed33787\n",
      "  Stored in directory: c:\\users\\86158\\appdata\\local\\pip\\cache\\wheels\\54\\04\\f7\\55704a9d374ed923785a4fdc0ef00151fa25306b3b93345532\n",
      "  Building wheel for pygetwindow (setup.py): started\n",
      "  Building wheel for pygetwindow (setup.py): finished with status 'done'\n",
      "  Created wheel for pygetwindow: filename=PyGetWindow-0.0.9-py3-none-any.whl size=11078 sha256=b2c2c042e0335d6faa39a2d7037c3b3dc6a70000ff144ca5e1e916623466c991\n",
      "  Stored in directory: c:\\users\\86158\\appdata\\local\\pip\\cache\\wheels\\91\\e3\\04\\184bda98ec7f7d5f0ba1f372bcf7b3ba86325151ae1dd690fe\n",
      "  Building wheel for pyscreeze (PEP 517): started\n",
      "  Building wheel for pyscreeze (PEP 517): finished with status 'done'\n",
      "  Created wheel for pyscreeze: filename=PyScreeze-0.1.28-py3-none-any.whl size=13009 sha256=7ea9b8f5875b9acea73ca2becc243d4a594ca6ce47e33f2d8ec382b7b813341a\n",
      "  Stored in directory: c:\\users\\86158\\appdata\\local\\pip\\cache\\wheels\\b1\\b0\\5c\\9fb5beb2d6c708479a670e92f4ab3b54523a15c9cd4a46e24e\n",
      "  Building wheel for PyTweening (setup.py): started\n",
      "  Building wheel for PyTweening (setup.py): finished with status 'done'\n",
      "  Created wheel for PyTweening: filename=pytweening-1.0.4-py3-none-any.whl size=5825 sha256=d7ac21965f2682b25369572c837850c6e4fb744b69957fc1d54864875191c2c1\n",
      "  Stored in directory: c:\\users\\86158\\appdata\\local\\pip\\cache\\wheels\\a2\\1b\\69\\dc477653ccc19228bf53af76c623e4e82e5dc1b6f78d5c4d35\n",
      "  Building wheel for mouseinfo (setup.py): started\n",
      "  Building wheel for mouseinfo (setup.py): finished with status 'done'\n",
      "  Created wheel for mouseinfo: filename=MouseInfo-0.1.3-py3-none-any.whl size=10905 sha256=c55a12d5042c7d83e9e62f4fe5536e7a54396880205d4a67996724de4be4447d\n",
      "  Stored in directory: c:\\users\\86158\\appdata\\local\\pip\\cache\\wheels\\d1\\72\\fb\\35f403de66285df8ecca7049bcc61bfb57aba0f76d1f08f7eb\n",
      "  Building wheel for pymsgbox (PEP 517): started\n",
      "  Building wheel for pymsgbox (PEP 517): finished with status 'done'\n",
      "  Created wheel for pymsgbox: filename=PyMsgBox-1.0.9-py3-none-any.whl size=7406 sha256=431440b97bfe1a2555fb55c2fd5db31f761083e90163bbd05da6e13c980dc7c0\n",
      "  Stored in directory: c:\\users\\86158\\appdata\\local\\pip\\cache\\wheels\\91\\28\\0d\\f4eb606d38276836237d6dc2abf094241e6db5682a126e0389\n",
      "  Building wheel for pyperclip (setup.py): started\n",
      "  Building wheel for pyperclip (setup.py): finished with status 'done'\n",
      "  Created wheel for pyperclip: filename=pyperclip-1.8.2-py3-none-any.whl size=11107 sha256=a06e970bca9cb7d8e05410aba79e57439c0e7f9873f33fe55ecffc15307e7fc3\n",
      "  Stored in directory: c:\\users\\86158\\appdata\\local\\pip\\cache\\wheels\\7f\\1a\\65\\84ff8c386bec21fca6d220ea1f5498a0367883a78dd5ba6122\n",
      "  Building wheel for pyrect (setup.py): started\n",
      "  Building wheel for pyrect (setup.py): finished with status 'done'\n",
      "  Created wheel for pyrect: filename=PyRect-0.2.0-py2.py3-none-any.whl size=11167 sha256=62e7bd212dfa9b1ef8e72b1f7d4a142f6acf5ccf9461268b170b06dda3cfd2d2\n",
      "  Stored in directory: c:\\users\\86158\\appdata\\local\\pip\\cache\\wheels\\1b\\c1\\cc\\3d6515746ab138a303b6b5d38181399703488f8109b734e768\n",
      "Successfully built pyautogui pygetwindow pyscreeze PyTweening mouseinfo pymsgbox pyperclip pyrect\n",
      "Installing collected packages: pyrect, pyperclip, PyTweening, pyscreeze, pymsgbox, pygetwindow, mouseinfo, pyautogui\n",
      "Successfully installed PyTweening-1.0.4 mouseinfo-0.1.3 pyautogui-0.9.53 pygetwindow-0.0.9 pymsgbox-1.0.9 pyperclip-1.8.2 pyrect-0.2.0 pyscreeze-0.1.28\n"
     ]
    }
   ],
   "source": [
    "!pip install pyautogui"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "af3725dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyautogui\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b1baf13c",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'pyautogui' has no attribute 'keyllp'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-11-5ddae680f801>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0mpyautogui\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkeyDown\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'enter'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[0mtime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0.5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0mpyautogui\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkeyllp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'enter'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m: module 'pyautogui' has no attribute 'keyllp'"
     ]
    }
   ],
   "source": [
    "time.sleep(10)\n",
    "pyautogui.typewrite('python.org',0.5)\n",
    "time.sleep(1)\n",
    "pyautogui.keyDown('enter')\n",
    "time.sleep(0.5)\n",
    "pyautogui.keyllp('enter')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a834630d",
   "metadata": {},
   "source": [
    "## 课后作业："
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6ff9c32",
   "metadata": {},
   "source": [
    "* P61"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "34596e18",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3c0e52aa",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:Milliways\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels：\")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bf3279cf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels：Hitch-hiker\n",
      "i\n",
      "e\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels：\")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "63551aa1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels：Galaxy\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels：\")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "98ecb34e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels：Sky\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels：\")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42b795c6",
   "metadata": {},
   "source": [
    "* P67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0e19a704",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "65499e1b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "plist.pop(0)\n",
    "plist.remove(\"'\")\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "plist.insert(2,plist.pop(3))\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e04cd01a",
   "metadata": {},
   "source": [
    "* P81"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f00e9c33",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "new_phrase = ''.join(plist[1:3])\n",
    "new_phrase = new_phrase + ''.join([plist[5],plist[4],plist[7],plist[6]])\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1b943c0c",
   "metadata": {},
   "source": [
    "* P89列表：更新我们已经知道些什么"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3015a898",
   "metadata": {},
   "source": [
    "|  列表的方法 |  Description  |     使用方法    |      备注     |\n",
    "| ----------  | ------------------| ------------------- | ----------------- |\n",
    "|  append  |   Append object to the end of the list.  | list.append(object) | 注意：增加在末尾！|\n",
    "|  clear  |    Remove all items from list.| list.clear(self)| 注意：将元素清空|\n",
    "|  copy   |   Return a shallow copy of the list.   | list.copy(self)  |注意：不等价于 = |\n",
    "|  count   |  Return number of occurrences of value. | list.count(self,value)  | 注意：返回的是某个元素在列表里面的个数 |\n",
    "|  extend  |  Extend list by appending elements from the iterable.  | list.extend(self, iterable) | 注意：在list的末尾添加元素 |\n",
    "|  index   | Return first index of value.  | list.index(self, value)  | 注意：返回的是元素在列表中的第一个位置 |\n",
    "|  insert  | Insert object before index.   | list.insert(self, index, object)   |注意： 向指定的地方添加元素 |\n",
    "|  pop   |  Remove and return item at index (default last). | list.pop(self, index=-1)  |注意：删除列表尾部的元素,返回删除的元素 |\n",
    "|  remove |  Remove first occurrence of value. | list.remove(self, value) | 注意：删除的是第一次出现的元素，如果元素不存在会报错  |\n",
    "|  reverse  | Reverse *IN PLACE*.    | list.reverse(self) | 注意：将列表进行翻转  |\n",
    "|  sort    | Sort the list in ascending order and return None. |list.sort(self)|注意：对列表进行排序，反向标志可以设置为按降序排序 |"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b136b1ea",
   "metadata": {},
   "source": [
    "|  列表 | 总结  | \n",
    "| ----------  | ------------------|\n",
    "|1.|列表认识中括号记法，可以用中括号来记法从任何列表选择单个对象。|\n",
    "|2.|与很多其他编程语言类似，Python从0开始计数，所以列表中的第一个对象位于索引位置0，第2个对象处于索引位置1。|\n",
    "|3.|Python允许从任意两端索引列表。使用-1会选择列表中的最后一项，-2会选择倒数第2个对象。|\n",
    "|4.|列表支持在中括号记法中指定开始、结束和步长值，可以提供列表的切片（或片段）。|\n",
    "|5.|只要需要存储任何相关对象的一个集合，列表就是很好的选择。|\n",
    "|6.|如果有一组类似的对象，需要把它们存储在一个数据结构中，列表就是理想的选择。|\n",
    "|7.|列表很擅长存储相关字母的集合，如vowels列表。如果数据是一个数字集合，列表也是很好的选择。|\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5b9e932f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
